import UnitSpellEvent from '@/event/UnitSpellEvent';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';

interface IParam {
    damagePool: unit[];
    effect: effect;
}

export default class Item_脚滑之靴 {
    static id = 'Atlx';
    static onInterval(p: HitFlyConfig<IParam>) {
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 125);
        for (let e of es) {
            if (!p.other.damagePool.includes(e)) {
                p.other.damagePool.push(e);
                DamageSystemInstance.applyIceDamage(e, p.caster, 600);
            }
        }
    }
    static onEnd(p: HitFlyConfig<IParam>) {
        DestroyEffect(p.other.effect);
        p.other = null;
    }
    static 释放(x: number, y: number, 来源?: unit, 目标?: unit, d?: any) {
        let angle = MathUtil.angleBetweenCoords(GetUnitX(来源), GetUnitY(来源), x, y);
        let other: IParam = {
            damagePool: [],
            effect: AddSpecialEffectTarget('Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveMissile.mdl', 来源, 'foot'),
        };
        MovementCommon.hitFly({
            target: 来源,
            caster: 来源,
            speed: 900,
            maxHeight: 0,
            angle: angle,
            distance: 600,
            onInterval: Item_脚滑之靴.onInterval,
            onEnd: Item_脚滑之靴.onEnd,
            other,
        });
    }
    constructor() {
        se.onUnitSpellEffect(Item_脚滑之靴.spellEffect, Item_脚滑之靴.id);
    }
    static spellEffect(this: void, d: UnitSpellEvent) {
        Item_脚滑之靴.释放(d.spellTargetX, d.spellTargetY, d.trigUnit, d.spellTargetUnit, d);
    }
}
